package com.lt.interactive.wechat.controller;


import com.lt.bcra.exception.BaseException;
import com.lt.bcra.result.ResultData;
import com.lt.interactive.wechat.service.WechatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

@Api(tags = "微信服务")
@RestController
@RequestMapping("/sso/wechat")
public class BcraWechatController {

    @Autowired
    private WechatService wechatService;

    private static Logger log = LoggerFactory.getLogger(BcraWechatController.class);


    @ApiOperation("微信登录获取二维码")
    @GetMapping("getLoginParam")
    @ResponseBody
    public ResultData genQrConnect() throws BaseException {
        if (log.isDebugEnabled()) log.debug("微信登录获取二维码 BcraWechatController");
        return wechatService.getQrCode();
    }


    @ApiOperation("微信回调登录注册")
    @GetMapping("callback")
    public void callback(String code, String state,HttpServletResponse response,HttpServletRequest request) throws IOException {
        if (log.isDebugEnabled()) log.debug("微信回调登录 BcraWechatController");
        wechatService.callBack(code,state,response,request);
    }
}
